#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QDebug>
#include "roundmenuwidget.h"

class SimpleTestWindow : public QWidget
{
    Q_OBJECT

public:
    SimpleTestWindow(QWidget *parent = nullptr) : QWidget(parent)
    {
        setupUI();
    }

private slots:
    void onMenuItemClicked(int index)
    {
        statusLabel->setText(QString("点击了菜单项: %1 - 正在聚集").arg(index + 1));
        qDebug() << "菜单项被点击:" << index;
        
        // 点击图标后触发聚集动画
        roundMenu->expandMenu();
    }void onMenuToggled(bool expanded)
    {
        statusLabel->setText(expanded ? "菜单已展开" : "菜单已收起");
    }
      void addTestItem()
    {
        static int count = 0;
        count++;
        roundMenu->addMenuItem(QString("测试%1").arg(count), 
                              QString("测试项目 %1").arg(count));
    }    void resetToImageStyle()
    {
        // 重置为分散布局风格
        MenuStyleConfig style = roundMenu->getMenuStyle();
        style.showBackground = false;
        style.useRoundMenuItems = true;
        style.enableRotationAnimation = false;  // 分散布局不需要旋转
        style.useScatteredLayout = true;  // 启用分散布局
        style.showCenterButton = false;  // 不显示中心按钮
        style.centerButtonColor = QColor(255, 130, 71);
        style.centerButtonHoverColor = QColor(255, 100, 41);
        style.menuItemBgScale = 1.2;
        style.outerRadiusScale = 0.9;
        style.innerRadiusScale = 0.1;
        roundMenu->setMenuStyle(style);
        statusLabel->setText("已重置为分散布局风格");
    }
      void toggleLayoutMode()
    {
        MenuStyleConfig style = roundMenu->getMenuStyle();
        style.useScatteredLayout = !style.useScatteredLayout;
        
        if (style.useScatteredLayout) {
            // 分散布局模式
            style.showCenterButton = false;
            style.enableRotationAnimation = false;
            style.menuItemBgScale = 1.2;
            style.outerRadiusScale = 0.9;
            style.innerRadiusScale = 0.1;
            statusLabel->setText("已切换到分散布局模式");
        } else {
            // 圆形菜单模式
             .showCenterButton = true;
            style.enableRotationAnimation = true;
            style.menuItemBgScale = 0.8;
            style.outerRadiusScale = 0.85;
            style.innerRadiusScale = 0.25;
            statusLabel->setText("已切换到圆形菜单模式");
        }
        
        roundMenu->setMenuStyle(style);
    }
      void triggerGatherAnimation()
    {
        // 手动触发聚集/分散动画
        if (roundMenu->gatherProgress() < 0.5) {
            // 当前是分散状态，触发聚集
            roundMenu->expandMenu();
            statusLabel->setText("正在聚集成圆形...");
        } else {
            // 当前是聚集状态，触发分散
            roundMenu->collapseMenu();
            statusLabel->setText("正在分散...");
        }
    }
    
    void toggleCenterButtonBehavior()
    {
        // 切换中心按钮在分散布局中的显示状态
        MenuStyleConfig style = roundMenu->getMenuStyle();
        style.showCenterButtonInScattered = !style.showCenterButtonInScattered;
        roundMenu->setMenuStyle(style);
        
        if (style.showCenterButtonInScattered) {
            statusLabel->setText("中心按钮已启用 - 可点击控制收起");
        } else {
            statusLabel->setText("中心按钮已禁用");
        }
    }

private:    void setupUI()
    {
        setWindowTitle("圆形菜单简单测试");
        setMinimumSize(800, 600);
        
        // 设置深色背景
        setStyleSheet("QWidget { background-color: #2C2C2E; color: white; }"
                     "QPushButton { background-color: #3A3A3C; border: 1px solid #48484A; "
                     "border-radius: 8px; padding: 8px; color: white; }"
                     "QPushButton:hover { background-color: #48484A; }"
                     "QLabel { color: white; }");
        
        QVBoxLayout *layout = new QVBoxLayout(this);
        layout->setContentsMargins(20, 20, 20, 20);
        
        // 创建圆形菜单
        roundMenu = new RoundMenuWidget(this);
        roundMenu->setMinimumSize(500, 500);        // 设置样式为匹配图片效果 - 分散布局，点击后聚集
        MenuStyleConfig style = roundMenu->getMenuStyle();
        style.showBackground = false;  // 透明背景让深色窗口背景显示
        style.useRoundMenuItems = true;  // 使用圆形菜单项
        style.enableRotationAnimation = false;  // 分散布局不需要旋转动画        style.useScatteredLayout = true;  // 启用分散布局模式
        style.showCenterButton = true;  // 显示中心按钮
        style.showCenterButtonInScattered = true; // 在分散布局中显示中心按钮
        style.centerButtonColor = QColor(255, 130, 71);  // 橙色中心按钮
        style.centerButtonHoverColor = QColor(255, 100, 41);
        style.menuItemBgScale = 1.2;  // 调整菜单项大小
        style.outerRadiusScale = 0.9;  // 适合分散布局的半径
        style.innerRadiusScale = 0.1;  // 较小的内圆半径
        style.animationDuration = 1000;  // 较慢的动画让聚集效果更明显
        roundMenu->setMenuStyle(style);
        
        // 菜单开始时就展开，显示分散的图标
        roundMenu->expandMenu();
        
        // 添加彩色菜单项（模拟图片中的效果）
        roundMenu->addMenuItem("Pinwheel", "彩色风车", QPixmap(), QColor(138, 43, 226));   // 紫色
        roundMenu->addMenuItem("Firefox", "火狐浏览器", QPixmap(), QColor(255, 69, 0));    // 橙红色
        roundMenu->addMenuItem("Fox", "可爱狐狸", QPixmap(), QColor(255, 99, 71));       // 珊瑚色
        roundMenu->addMenuItem("Monkey", "小猴子", QPixmap(), QColor(50, 205, 50));      // 绿色
        roundMenu->addMenuItem("Money", "钱币", QPixmap(), QColor(255, 165, 0));         // 橙色
        roundMenu->addMenuItem("Penguin", "企鹅", QPixmap(), QColor(70, 130, 180));     // 钢蓝色
        roundMenu->addMenuItem("RCKit", "遥控工具", QPixmap(), QColor(220, 20, 60));     // 深红色
        roundMenu->addMenuItem("Chrome", "谷歌浏览器", QPixmap(), QColor(0, 191, 255));   // 深天蓝色
        roundMenu->addMenuItem("Linux", "企鹅系统", QPixmap(), QColor(255, 140, 0));     // 深橙色
          // 状态标签
        statusLabel = new QLabel("分散布局圆形菜单演示 - 点击圆形图标进行交互", this);
        statusLabel->setAlignment(Qt::AlignCenter);
        statusLabel->setStyleSheet("font-size: 16px; padding: 10px;");
        
        // 控制按钮容器
        QWidget *buttonWidget = new QWidget;
        QHBoxLayout *buttonLayout = new QHBoxLayout(buttonWidget);        QPushButton *addBtn = new QPushButton("添加菜单项", this);
        QPushButton *toggleBtn = new QPushButton("切换菜单", this);
        QPushButton *resetBtn = new QPushButton("重置样式", this);
        QPushButton *layoutBtn = new QPushButton("切换布局模式", this);
        QPushButton *gatherBtn = new QPushButton("聚集/分散动画", this);
        QPushButton *centerBtnToggle = new QPushButton("中心按钮开关", this);
        
        buttonLayout->addWidget(addBtn);
        buttonLayout->addWidget(toggleBtn);
        buttonLayout->addWidget(resetBtn);
        buttonLayout->addWidget(layoutBtn);
        buttonLayout->addWidget(gatherBtn);
        buttonLayout->addWidget(centerBtnToggle);        // 连接信号
        connect(roundMenu, &RoundMenuWidget::menuItemClicked, 
                this, &SimpleTestWindow::onMenuItemClicked);
        connect(roundMenu, &RoundMenuWidget::menuToggled, 
                this, &SimpleTestWindow::onMenuToggled);
        connect(addBtn, &QPushButton::clicked, this, &SimpleTestWindow::addTestItem);
        connect(toggleBtn, &QPushButton::clicked, roundMenu, &RoundMenuWidget::toggleMenu);
        connect(resetBtn, &QPushButton::clicked, this, &SimpleTestWindow::resetToImageStyle);
        connect(layoutBtn, &QPushButton::clicked, this, &SimpleTestWindow::toggleLayoutMode);
        connect(gatherBtn, &QPushButton::clicked, this, &SimpleTestWindow::triggerGatherAnimation);
        connect(centerBtnToggle, &QPushButton::clicked, this, &SimpleTestWindow::toggleCenterButtonBehavior);
        
        // 布局
        layout->addWidget(roundMenu, 1);
        layout->addWidget(statusLabel);
        layout->addWidget(buttonWidget);
    }

private:
    RoundMenuWidget *roundMenu;
    QLabel *statusLabel;
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    
    SimpleTestWindow window;
    window.show();
    
    return app.exec();
}

#include "simple_test.moc"
